package com.sls.web.manager.action.recharge;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.page.Pagination;
import com.sls.web.manager.pojo.UserInfoVO;
import com.sls.web.manager.recharge.pojo.CardStatistics;
import com.sls.web.manager.recharge.querybean.CardStatisticsQuery;
import com.sls.web.manager.recharge.querybean.SystemProductQuery;
import com.sls.web.manager.recharge.service.CardStatisticsService;
import com.sls.web.manager.recharge.service.OperationService;
import com.sls.web.manager.recharge.service.SystemProductService;

/**
 * 卡密产品管理
 * 
 * @author sxf
 * 
 */
public class CardManagementAction extends SuperAction {
	private static final long serialVersionUID = 2256195775591798705L;

	@Resource(name = "cardStatisticsService")
	private CardStatisticsService statisticsService;
	@Resource(name = "systemProductService")
	private SystemProductService systemProductService;
	@Resource(name = "operationService")
	private OperationService operationService;

	// 列表页面使用
	private Pagination<?> page;
	private CardStatisticsQuery statisticsQuery;
	private String cardName;

	private SystemProductQuery systemProductQuery;

	// 销量统计页面使用
	private String orderDate;// 订单日期

	public String list() throws Exception {
		if (systemProductQuery == null) {
			systemProductQuery = new SystemProductQuery();
			systemProductQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
			systemProductQuery.setPageSize(Constants.INIT_PAGESIZE);
		}
		UserInfoVO userInfoVO = getCurrentOperator();
		if (StringUtils.isNotBlank(cardName)) {
			systemProductQuery.setName(cardName);
		}
		page = systemProductService.queryCardMangementPage(systemProductQuery,
				userInfoVO);

		// if (StringUtils.isNotBlank(cardName)) {
		// query.setCardName(cardName);
		// }
		// query.setStatus(1);// 1:库存统计
		// page = statisticsService.queryPage(query, getUserInfoVO());

		return "list";
	}

	/**
	 * 销售统计
	 * 
	 * @return
	 * @throws Exception
	 */
	public String saleStatistics() throws Exception {
		if (statisticsQuery == null) {
			statisticsQuery = new CardStatisticsQuery();
			statisticsQuery.setCurrentPage(1);
			statisticsQuery.setPageSize(5);
		}

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if (StringUtils.isBlank(orderDate)) {
			orderDate = sdf.format(new Date());
		}

		statisticsQuery.setCreateDate(orderDate);
		statisticsQuery.setStatus(2);// 2:销量统计
		page = statisticsService.queryPage(statisticsQuery,
				getCurrentOperator());
		if (page == null) {
			page = new Pagination<CardStatistics>();
		}

		return "sale";
	}

	public Pagination<?> getPage() {
		return page;
	}

	public void setPage(Pagination<?> page) {
		this.page = page;
	}

	public String getCardName() {
		return cardName;
	}

	public void setCardName(String cardName) {
		this.cardName = cardName;
	}

	public String getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(String orderDate) {
		this.orderDate = orderDate;
	}

	public SystemProductQuery getSystemProductQuery() {
		return systemProductQuery;
	}

	public void setSystemProductQuery(SystemProductQuery systemProductQuery) {
		this.systemProductQuery = systemProductQuery;
	}

	public CardStatisticsQuery getStatisticsQuery() {
		return statisticsQuery;
	}

	public void setStatisticsQuery(CardStatisticsQuery statisticsQuery) {
		this.statisticsQuery = statisticsQuery;
	}
}
